var BaseNode = require('./../../FrameWork/Component/BaseNode');
var _ = require('./../../FrameWork/we_underscore');
cc.Class({
    extends: BaseNode,
    /**开始播放滚动动画*/
    playAnim(_middPos, _endPos) {
        this.doSequenceAnim(this.getAction(_middPos, _endPos));
    },
    /**开始播放滚动动画*/
    playAnimDelay(_delayT, _startCb, _middPos, _endPos, _middCb, _endCb) {
        let actArray = this.getAction(_middPos, _endPos, _middCb, _endCb);
        actArray.unshift(cc.callFunc(_startCb));
        actArray.unshift(cc.delayTime(_delayT));
        var actAll = cc.sequence(actArray);
        actAll.easing(cc.easeSineOut(3));
        this.doAction(actAll);
    },

    getRandSymbol() {
        return _.random(0, 2) > 1 ? -1 : 1
    },

    getAction(_middPos, _endPos, _middCb, _endCb) {
        let actArray = [];
        let actTime = 0.5;
        actArray.push(cc.fadeIn(0.01, 255));
        actArray.push(cc.spawn([cc.moveTo(actTime, _middPos), cc.rotateBy(actTime, this.getRandSymbol() * _.random(90, 360))]));
        actArray.push(cc.spawn([cc.delayTime(actTime * 2), cc.rotateBy(actTime * 0.5, this.getRandSymbol() * _.random(0, 90))]));

        if (_middCb) {
            actArray.push(cc.callFunc(_middCb));
        }
        actArray.push(cc.spawn([cc.moveTo(actTime, _endPos),
            cc.sequence(cc.delayTime(actTime * 0.8), cc.fadeOut(actTime * 0.2)),
            cc.rotateBy(actTime, this.getRandSymbol() * _.random(90, 360))
        ]));
        actArray.push(cc.fadeOut(actTime * 2));
        if (_endCb) {
            actArray.push(cc.callFunc(_endCb));
        }
        actArray.push(cc.callFunc(function() {
            this.node.destroy()
        }.bind(this)));
        return actArray;
    }
});